using System.Text.RegularExpressions;

namespace STHPMS1.Common.C_Utils
{
	public class Regexlib
	{
		/// <summary>
		/// 验证数字格式(可以小数)
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		public static bool IsNumber (string input)
		{
			string pattern = "^-?\\d+$|^(-?\\d+)(\\.\\d+)?$";
			return IsMatch (pattern, input);
		}

		/// <summary>
		/// 验证日期格式
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		public static bool IsDate (string input)
		{
			string pattern = @"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-9]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$";
			return IsMatch (pattern, input);
		}

		public static bool IsMatch (string pattern, string input)
		{
			if (input == null || input == "")
				return false;
			Regex regex = new Regex (pattern);
			return regex.IsMatch (input);
		}
	}
}
